package com.loong.order.handler;

import com.loong.common.utils.TransformUtils;
import com.loong.order.business.OrderDeliveryBusiness;
import com.loong.order.common.forehead.param.OrderDeliveryForeheadParam;
import com.loong.order.common.forehead.result.OrderDeliveryResult;
import com.loong.order.model.OrderDelivery;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:  订单配送信息服务
 * @Author: hzp
 * @Date: 2020-12-31 9:35
 */
@Slf4j
@Component
public class OrderDeliveryHandler {
    @Resource
    private OrderDeliveryBusiness orderDeliveryBusiness;

    /**
     * 保存配送信息
     * @param orderDeliveryForeheadParam 配送信息
     */
    public void save(OrderDeliveryForeheadParam orderDeliveryForeheadParam){
        orderDeliveryBusiness.save(TransformUtils.transform(orderDeliveryForeheadParam, OrderDelivery.class));
    }

    public OrderDeliveryResult findByOrderId(Long orderId){
        return TransformUtils.transform(orderDeliveryBusiness.findBy("orderId",orderId),OrderDeliveryResult.class);
    }

    /**
     * 更新配送信息
     * @param orderDeliveryForeheadParam 配送信息
     */
    public void update(OrderDeliveryForeheadParam orderDeliveryForeheadParam) {
        orderDeliveryBusiness.updateByPrimaryKeySelective(TransformUtils.transform(orderDeliveryForeheadParam, OrderDelivery.class));
    }

    /**
     * 根据ids删除
     * @param orderDeliveryIdList list->（1,2,3）
     */
    public void deleteIds(List<Long> orderDeliveryIdList) {
        orderDeliveryBusiness.deleteByIds(StringUtils.join(orderDeliveryIdList,","));
    }
}
